package net.inteidee.test;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;


@ManagedBean(name="beanNavigation")
public class BeanNavigation {
	
	@ManagedProperty(value="#{beanLogin}")
	BeanLogin beanLogin;
	
	

	
	public String fromHomeToFatture(){

		if(checkIfIsAAuthorizedUser("/pages/fatture.xhtml"))
			return "authorized user";

		return "unauthorized user";
	}
	
	public String fromHomeToOrdini(){
		
		if(checkIfIsAAuthorizedUser("/pages/ordini.xhtml"))
			return "authorized user";

		return "unauthorized user";
	}
	
	public String fromHomeToUtenti(){
		
		if(checkIfIsAAuthorizedUser("/pages/utenti.xhtml"))
			return "authorized user";

		return "unauthorized user";
	}
	
	private boolean checkIfIsAAuthorizedUser(String path){
		
		
		String ruoloNecessario = XmlReader.getValueFromConfigurationXmlFile("urls",path);
		String ruoloAttuale = beanLogin.getSamplePrincipal().getRuolo();
		
		if(ruoloNecessario.equals(ruoloAttuale))
			return true;
		
		return false;
	}

	public BeanLogin getBeanLogin() {
		return beanLogin;
	}

	public void setBeanLogin(BeanLogin beanLogin) {
		this.beanLogin = beanLogin;
	}
	
	
	
}
